<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

function pdf_create($html, $filename, $stream=TRUE)
{
    require_once("dompdf/dompdf_config.inc.php");
    spl_autoload_register('DOMPDF_autoload');
    ini_set("memory_limit", "64M"); 
    
    $dompdf = new DOMPDF();
    //$dompdf->set_paper("A4", "portrait");
    $dompdf->set_base_path("./");
    $dompdf->load_html($html);   
    $dompdf->render();
    if ($stream) {

        //$dompdf->stream(url_title($filename).".pdf", array("Attachment" => 0)); //use this to display on browser
        $dompdf->stream(url_title($filename).".pdf");

    } else {
        $CI =& get_instance();
        $CI->load->helper('file');
		$file_name = url_title(character_limiter($filename, 120,"").".pdf");
        //write_file("./invoices_temp/invoice_$filename.pdf", $dompdf->output());
		write_file("./".PDF_FOLDER.$file_name, $dompdf->output());
		return $file_name;
    }
}

?> 